<template>
    <div class="viewpost rounded">
        <div class="viewpost-viewpostOpr">
            <button type="button" class="btn-sm btn-outline-secondary"
            @click.stop="goBack"
            >返回</button>
        </div>
        <div class="articlesContent mt-2">
            <div v-if="artContent.length != 0" class="art-content ql-editor" v-html="artContent" ></div>
            <div 
            style="display: flex; justify-content: center ; align-items: center;"
            v-else>什么都没有～</div>
        </div>
    </div>
</template>

<script>
import { getArticle } from "../../../../api/interface/filesystem.js";
import { freshToken } from "../../../../api/interface/token.js";
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

export default {
    data(){
        return {
            artContent: ""
        };
    },
    inject:["noteAgent"],
    methods:{
        goBack(){
            let note = this.noteAgent();
            this.$store.commit("setcurrentViewpost" , 
            {
                constent: null,
                index: null
            }
            );
            note.popup.checkFile = false;
            // this.explorer().current = this.$store.getters.getcurrentIndex;
            this.noteAgent().$refs.exploreFile.current = this.$store.getters.getcurrentIndex;
        },
        fetchData(){
            let that = this;
            let view_curitem = this.$store.getters.getcurrentViewpost; 
            let artParam = {};
            if( view_curitem.art_id ){
                artParam.art_id = view_curitem.art_id
            }
            getArticle(artParam).then(res=>{
                console.log("获取文章：", res);
                if( res.data.code == 0 ){
                    this.artContent = res.data.data.content;
                    
                }

            }).catch(err=>{
                this.$httpError.checkResStatus(err.data,function(){
                    
                    //重新请求生成token
                    freshToken().then(res=>{
                        
                        localStorage.setItem("token", res.data.data.token);
                        that.fetchData();
                    })
                },that)
            });
        }
    },
    mounted() {
        this.fetchData();
    },
}
</script>

<style lang="scss" >


.viewpost{


background-color: white;

min-width: 500px;
min-height: 500px;

}
.viewpost-viewpostOpr{
    display: inline-block;
    position: absolute;
    left: 13%;
    top: 10%;
}
.articlesContent{
    width: 100%;
    height: 100%;
    padding: 3em;
    .art-content{
        white-space: pre-wrap;
        
    }
}
</style>